<?php
/**
 * Profiles View for Congregation Component
 * 
 * @package    Joomla.Tutorials
 * @subpackage Components
 * @link http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_4
 * @license		GNU/GPL
 */

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view' );

/**
 * Profiles View
 *
 * @package    Joomla.Tutorials
 * @subpackage Components
 */
class CongregationViewProfiles extends CongregationView
{
	/**
	 * Sharings view display method
	 * @return void
	 **/

	 
	function display($tpl = null)
	{
		
		
		JToolBarHelper::deleteList();
		JToolBarHelper::editListX();
		JToolBarHelper::addNewX();
		JToolBarHelper::back(JText::_('Back'), JRoute::_( 'index.php?option=com_congregation'));

		JHTML::_('behavior.tooltip');
		
		$context = 'administrator.com_congregation.profiles.default';
		$order_by = $this->_mainframe->getUserStateFromRequest( $context.'order_by', 'order_by', 'm.lname', 'string' );
		$order_dir = $this->_mainframe->getUserStateFromRequest( $context.'order_dir', 'order_dir', '', 'string' );
		$pid_cid = JRequest::getVar('pid_cid',$this->_mainframe->getUserStateFromRequest( $context.'pid_cid', 'pid_cid', '', 'string' ));

		$search = $this->_mainframe->getUserStateFromRequest( $context.'search', 'search', '', 'string' );
		
		if (strpos($search, '"') !== false) {
			$search = str_replace(array('=', '<'), '', $search);
		}
		$search = JString::strtolower($search);
	
		$limit		= $this->_mainframe->getUserStateFromRequest( $context.'limit', 'limit', $this->_mainframe->getCfg('list_limit'), 'int' );
		$limitstart = $this->_mainframe->getUserStateFromRequest( $context.'limitstart', 'limitstart', 0, 'int' );


		$pid_cid_a = explode(':', $pid_cid);
		$p_id = $pid_cid_a['0'];
		$c_id = isset($pid_cid_a['1'])? $pid_cid_a['1']: '';
		JRequest::setVar('limit',       (int) $limit);
		JRequest::setVar('limitstart',  (int) $limitstart);
		JRequest::setVar('search',      $search);
		JRequest::setVar('order_by',        $order_by);
		JRequest::setVar('order_dir',        $order_dir);
		JRequest::setVar('c_id',      $c_id);
		JRequest::setVar('p_id',      $p_id);


		$lists = array();
		$model = $this->getModel();
		$lists['houses'] = $model->getHouseList();
	
		

		// table ordering
		$lists['order_by']	= $order_by;
		$lists['order_dir']		= $order_dir;

		// search filter
		$lists['search']= $search;    
		
		$total = 0;
		if($items		= & $this->get( 'Data'))
		{
			$total		= & $this->get( 'Total' );
		}
		JToolBarHelper::title(   JText::_( 'Profile manager' ), 'generic.png' );
		
		jimport('joomla.html.pagination');
		$pagination = new JPagination($total, $limitstart, $limit);
		$this->assignRef('items',		$items);
		$this->assignRef('pagination',  $pagination);
		$this->assignRef('lists',       $lists);
		$this->assignRef('c_id',       $c_id);
		$this->assignRef('p_id',       $p_id);
		$this->assignRef('pid_cid',       $pid_cid);
		
		parent::display($tpl);
	}
	

}
